{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 提示词 #\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    api_key=\"ollama\",\n",
    "    base_url=\"http://192.168.20.43:11434/v1\"\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "顾问1:无锡我们现在在天津的话有一个。\n",
      "客户1:海河边海河金茂府，这个房子就是这种的，对，这个是我们。\n",
      "顾问1:金茂府它的一个特别大的一个核心了，我们在全国的第一座金茂府在哪儿？\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<thinking>\n",
      "在回答这个问题之前，我们需要了解两个关键数据集：每家加油站每小时的净利润和所有加油站的总净利润。问题让我们考虑将非24小时营业的加油站调整为24小时模式的可能性。如果增加的时间段能带来更多的利润，并且其运营成本不足以抵消额外收益，那么这样做可能是合理的。我们可以通过对比特定时间段（通常晚上的低需求时段）的净利润来预测潜在的增长。因此，我们需要采取以下步骤：\n",
      "\n",
      "1. 获取所有加油站每小时的净利润数据\n",
      "2. 获取所有非24小时营业的加油站的具体运营时间表和相关成本\n",
      "3. 根据具体时间和利润数据，计算每家非24小时营业加油站额外营业的时间能带来的预期收益。\n",
      "4. 每次增加时段时应考虑的附加成本可能包括人工费用、维持运行的成本及可能需要的增加投资（如延长照明设施或停车场）等。\n",
      "5. 筛选并对比上述信息，确认有哪几家加油站调整为24小时能显著提高盈利能力。\n",
      "\n",
      "我将首先开始第1步骤，并使用get_profit和get_TotalProfit API获取数据。\n",
      "</thinking>\n",
      "\n",
      "<Chain of Thought>\n",
      "为了进行对比以找出应该实施延长营业时间政策的加油站列表，首先获取所有站点每小时的净利润数据。然后，我们需要识别那些非24小时运营的商店，并确定它们没有营业的时间里每小时可能产生的潜在收益。最后我们计算在特定时间段额外的营业能带来的预期利润与运行这些额外时段的成本之间的差额。\n",
      "</Chain of Thought>\n",
      "\n",
      "<reflection>\n",
      "根据问题描述，我已经概述了分析过程的大致步骤：从数据获取开始，识别盈利机会，并最终确定应该调整时间表以延长服务时长的站点。在执行过程中我考虑使用API（get_profit, get_TotalProfit）来汇总必要的数据信息以及对加油站具体运营时间和成本有直接了解的可能性。然而需要注意的是，这一分析假设了有明确的数据可用并具有一定的准确性。另外，在评估成本时还可能需要考虑更为长远的影响和不确定性因素。\n",
      "</reflection>\n",
      "\n",
      "<output>\n",
      "依据当前的框架计划与API获取的方法，你需要执行以下步骤：\n",
      "\n",
      "1. 使用get_profit(GasStation_ID, time_period)获取每家加油站每小时净利润的数据\n",
      "2. 使用get_TotalProfit(time_period) 获取所有非24小时营业加油站特定时间未运营但可能带来利润的时间段数据（通常应考虑低需求时段的潜在收入）\n",
      "3. 对比这些时间段的净利润增加与额外运营成本，确定哪些站点调整至全天候营业能有效提升盈利\n",
      "\n",
      "按照这样的策略执行，可以得出应该实施延长营业时间政策的站点列表。最终结果基于数据的精准度和对成本效益分析的理解。\n",
      "</output>\n"
     ]
    }
   ],
   "source": [
    "def llm_relection_prompt(query, context_str):\n",
    "    prompt = f\"\"\"\\\n",
    "    You are an AI assistant designed to provide detailed, step-by-step responses. \\\n",
    "    <Context> is below. Given the context information and answer the query.\\\n",
    "    Your outputs should follow this structure:\\\n",
    "\n",
    "    1. Begin with a <thinking> section.\n",
    "    2. Inside the thinking section:\n",
    "        a. Briefly analyze the question and outline your approach.\n",
    "        b. Present a clear plan of steps to solve the problem.\n",
    "        c. Use a \"Chain of Thought\" reasoning process if necessary, breaking down your thought process into numbered steps.\n",
    "    3. Include a <reflection> section for each idea where you:\n",
    "        a. Review your reasoning.\n",
    "        b. Check for potential errors or oversights.\n",
    "        c. Confirm or adjust your conclusion if necessary.\n",
    "    4. Be sure to close all reflection sections.\n",
    "    5. Close the thinking section with </thinking>.\n",
    "    6. Provide your final answer in an <output> section, and close the output section with </output>\n",
    "\n",
    "    Always use these tags in your responses. Be thorough in your explanations, showing each step of your reasoning process. Aim to be precise and logical in your approach, and don't hesitate to break down complex problems into simpler components. Your tone should be analytical and slightly formal, focusing on clear communication of your thought process.\n",
    "\n",
    "    Remember: Both <thinking> and <reflection> MUST be tags and must be closed at their conclusion\n",
    "\n",
    "    Follow the OUTPUT FORMAT.\n",
    "    ---------------------\\\n",
    "    # Context #\n",
    "    {context_str}\n",
    "    ---------------------\\\n",
    "    # OUTPUT FORMAT #\n",
    "    <thinking>\n",
    "    some text.\n",
    "    </thinking>\n",
    "    <Chain of Thought>\n",
    "    some text.\n",
    "    </Chain of Thought>\n",
    "    <reflection> \n",
    "    some text.\n",
    "    </reflection> \n",
    "    <output>\n",
    "    some text.\n",
    "    </output>\n",
    "    ---------------------\\\n",
    "    \"\"\"\n",
    "    completion = client.chat.completions.create(\n",
    "        model=\"qwen2-7b-instruct\",\n",
    "        messages=[{'role': 'system', 'content': prompt},\n",
    "                  {'role': 'user', 'content': query}],\n",
    "        )\n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "# 测试用例\n",
    "context_str = \"\"\"\n",
    "    我们拥有每家加油站每小时的净利润数据，你可以通过API获取，get_profit(GasStation_ID, time_period)\n",
    "    我们也拥有全部加油站每小时的净利润数据，你可以通过API获取，get_TotalProfit(time_period)\n",
    "\"\"\"\n",
    "query1 = \"\"\"\n",
    "我们有的加油站是24小时的，有的不是， 那么我们有哪家加油站应该调整营业时间至24小时营业么？\n",
    "\"\"\"   \n",
    "query2 = \"求解x^2 + x +y = 3 且 x+y=1\"\n",
    "summary_text = llm_relection_prompt(query1, context_str) \n",
    "print(summary_text)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
